<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="UTF-8" />
		<title>鼠标跟随</title>
		<style type="text/css">
			div {
				width: 50px;
				height: 50px;
				background-color: #0C3;
				position: absolute;
			}
		</style>
	</head>

	<body>
		<div id="mydiv"></div>
		<script type="text/javascript">
			var mydiv = document.getElementById("mydiv");
			document.documentElement.onmousemove = function(ev) {
				var ev = ev || event;
				mydiv.style.left = ev.clientX - 25 + "px";
				mydiv.style.top = ev.clientY - 25 + "px";

			}
		</script>
	</body>

</html>